package sg.edu.nus.iss.vmcs.store;

/*
 * @editedby A0119952X - Singleton Design Pattern
 */
public class DrinkStoreController extends StoreController {
    private static DrinkStoreController instance;
    private DrinkStoreController() {
        super();
    }

    public static DrinkStoreController getInstance() {
        if (instance == null) {
            instance = new DrinkStoreController();
        }
        return instance;
    }

	@Override
	protected Store createStore() {
		return new DrinksStore();
	}

	@Override
	protected void initializeItem(Store store, StoreItem item) {
		StoreObject brand = item.getContent();
		StoreObject existingBrand = store.findObject(brand.getName());
		if (existingBrand != null) {
		    item.setContent(existingBrand);
		}
	}
	
	/**
	 * This method will sets the price for the {@link StoreItem} with the given index and price.
	 * @param idx the index of the StoreItem.
	 * @param pr the price of the StoreItem.
	 */
	public void setPrice(int idx, int pr)  {
		DrinksStoreItem item;

		item = (DrinksStoreItem) store.getStoreItem(idx);
		DrinksBrand bd;

		bd = (DrinksBrand) item.getContent();

		bd.setPrice(pr);
	}
	
	/**
	 * This method instructs the {@link DrinksStore} to dispense one drink, and then updates the 
	 * {@link sg.edu.nus.iss.vmcs.machinery.MachinerySimulatorPanel}&#46; It returns TRUE or FALSE to indicate whether dispensing
	 * was successful&#46;
	 * @param idx the index of the drinks to be dispensed&#46;
	 */
	public void dispenseDrink(int idx)  {
		DrinksStoreItem item;
		item = (DrinksStoreItem) getStoreItem(idx);
		item.decrement();
	}
	
	private DrinksStore getDrinksStore() {
		return (DrinksStore)store;
	}
}
